# 名称:Backdream
# 时间2022/12/20  16:34

from selenium.webdriver.common.by import By
from pages.base_page import BasePage



class CustomerPage(BasePage):
    #客户界面url
    url="/crm/index.php?m=customer"

    # 断言客户视图文本定位
    view_locaotor = (By.CSS_SELECTOR, "body > div.container > p > b")

    # 新建客户按钮
    add_customer_btn = (By.CSS_SELECTOR, "body > div.container > div.row > div:nth-child(1) > div > a")
    # 客户名称输入框
    input_name_locator = (By.ID, "name")
    # 保存按钮定位器
    save_btn = (By.CSS_SELECTOR, "#form1 > table > tfoot > tr > td > input:nth-child(1)")
    # 断言添加成功文本定位
    add_good = (By.CSS_SELECTOR, "body > div.container > div.alert.alert-success")
    # 查看客户详情按钮
    look_locator = (By.CSS_SELECTOR, "#form1 > table > tbody > tr:nth-child(1) > td:nth-child(12) > a:nth-child(1)")
    # 断言基本信息定位
    information_locator = (By.CSS_SELECTOR, "#tab1 > div.container2.top-pad > a")
    # 编辑按钮定位器
    edit_btn = (By.CSS_SELECTOR, "#form1 > table > tbody > tr:nth-child(1) > td:nth-child(12) > a:nth-child(2)")
    # 客户名称定位器
    edit_name_locator = (By.ID, "name")
    # 断言编辑成功定位
    information_edit_locator = (By.CSS_SELECTOR, "body > div.container > div.alert.alert-success")
    # 保存按钮定位
    save_locator = (By.CSS_SELECTOR, "#form1 > table > tfoot > tr > td > input.btn.btn-primary")
    # 勾选客户定位器
    chose_customer_locator = (By.CSS_SELECTOR, "#form1 > table > tbody > tr:nth-child(1) > td:nth-child(1) > input")
    # 批量操作定位
    use_customer_locator = (By.CSS_SELECTOR, "body > div.container > div.row > div:nth-child(1) > ul > div > a")
    # 批量删除按钮
    delete_many_btn = (By.ID, "delete")
    # 客户关怀按钮定位器
    customer_love_locator = (By.CSS_SELECTOR, "body > div.container > div.page-header > ul > li:nth-child(4) > a")

    # 断言客户视图文本
    def find_text(self):
        return self.driver.find_element(*self.view_locaotor).text

    # 点击新建客户按钮
    def add_customer(self):
        self.driver.find_element(*self.add_customer_btn).click()

    # 输入客户名称
    def input_name(self, name):
        self.driver.find_element(*self.input_name_locator).send_keys(name)

    # 点击保存按钮
    def click_save_btn(self):
        self.driver.find_element(*self.save_btn).click()

    # 断言添加成功文本
    def add_ok(self):
        return self.driver.find_element(*self.add_good).text

    # 查看客户详情按钮
    def look_customer(self):
        self.driver.find_element(*self.look_locator).click()

    # 断言查看详情基本信息
    def look_msg(self):
        return self.driver.find_element(*self.information_locator).text

    # 点击编辑按钮
    def edits_btn(self):
        self.driver.find_element(*self.edit_btn).click()

    # 编辑客户名称
    def edit_name(self, name):
        self.driver.find_element(*self.edit_name_locator).clear()
        self.driver.switch_to.alert.accept()
        self.driver.find_element(*self.edit_name_locator).send_keys(name)

    # 保存编辑客户按钮
    def save_edit(self):
        self.driver.find_element(*self.save_locator).click()

    # 断言编辑成功
    def mesg_ok(self):
        return self.driver.find_element(*self.information_edit_locator).text

    # 勾选客户
    def chose_customer(self):
        self.driver.find_element(*self.chose_customer_locator).click()

    # 批量操作客户
    def use_customer(self):
        self.driver.find_element(*self.use_customer_locator).click()

    # 点击批量删除
    def click_delete(self):
        self.driver.find_element(*self.delete_many_btn).click()
        self.driver.switch_to.alert.accept()

    # 点击客户关怀按钮
    def customer_love(self):
        self.driver.find_element(*self.customer_love_locator).click()

    # 新建关怀定位器
    add_love_btn = (By.CSS_SELECTOR, "body > div.container > div.row > div:nth-child(1) > div > a > i")

    # 点击新建客户关怀
    def add_love(self):
        self.driver.find_element(*self.add_love_btn).click()

    # 关怀主题定位器
    love_name_locator = (By.ID, "name")

    def love_name(self, name):
        self.driver.find_element(*self.love_name_locator).send_keys(name)

    # 选择客户输入框
    customer_name_locator = (By.ID, "customer_name")

    def customer_name(self, name):
        self.driver.find_element(*self.customer_name_locator).send_keys(name)

    # 关怀日期
    care_time_locator = (By.ID, "care_time")

    def care_time(self, time):
        self.driver.find_element(*self.care_time_locator).send_keys(time)

    # 保存并新建按钮
    save_new_btn = (By.CSS_SELECTOR,
                    "body > div.container > div.row > div > form > table > tfoot > tr > td:nth-child(2) > input:nth-child(2)")

    def save_new(self):
        self.driver.find_element(*self.save_new_btn).click()

    # 断言客户关怀成功
    custo_love_locator = (By.CSS_SELECTOR, "body > div.container > div.row > div > div")

    def custo_love(self):
        return self.driver.find_element(*self.custo_love_locator).text

    # 客户关怀页面内新建联系人定位器
    add_contact_locator = (By.CSS_SELECTOR,
                           "body > div.container > div.row > div > form > table > tbody > tr:nth-child(2) > td:nth-child(4) > a")

    def add_contact(self):
        self.driver.find_element(*self.add_contact_locator).click()

    # 跳转联系人定位
    contact_locator = (By.CSS_SELECTOR, "body > div.container > div.page-header > h4")

    def contact_text(self):
        return self.driver.find_element(*self.contact_locator).text

    # 点击联系人按钮
    contact_btn = (By.CSS_SELECTOR, "body > div.container > div.page-header > ul > li:nth-child(3) > a")

    def click_contact(self):
        self.driver.find_element(*self.contact_btn).click()

    # 联系人视图定位
    contact_view_locator = (By.CSS_SELECTOR, "body > div.container > p > b")

    def contact_view(self):
        return self.driver.find_element(*self.contact_view_locator).text

    # 新建联系人按钮
    add_contact_btn = (By.CSS_SELECTOR, "body > div.container > div.row > div:nth-child(1) > div > a > i")

    def click_add_contact(self):
        self.driver.find_element(*self.add_contact_btn).click()

    # 姓名框
    contact_name_locator = (By.ID, "name")

    def contact_name(self, name):
        self.driver.find_element(*self.contact_name_locator).send_keys(name)

    # 所属客户
    contact_customer_locator = (By.ID, "customer_name")

    def contact_customer(self):
        self.driver.find_element(*self.contact_customer_locator).click()

    # 勾选客户
    contact_chose_customer_locator = (
        By.CSS_SELECTOR, "#datas > tr:nth-child(1) > td:nth-child(1) > input[type=radio]:nth-child(1)")

    def contact_chose_customer(self):
        self.driver.find_element(*self.contact_chose_customer_locator).click()

    # 确定按钮
    ok_btn_locator = (By.CSS_SELECTOR,
                      "body > div:nth-child(8) > div.ui-dialog-buttonpane.ui-widget-content.ui-helper-clearfix > div > button:nth-child(1) > span")

    def ok_btn(self):
        self.driver.find_element(*self.ok_btn_locator).click()

    # 点击保存
    save_contact_btn = (By.CSS_SELECTOR,
                "body > div.container > div.row > div > form > table > tfoot > tr > td:nth-child(2) > input:nth-child(1)")
    def click_save(self):
        self.driver.find_element(*self.save_contact_btn).click()

    # 断言
    information_contact_locator = (By.CSS_SELECTOR, "body > div.container > div.alert.alert-success")
    def information_contact(self):
        return self.driver.find_element(*self.information_contact_locator).text

    # 勾选全部联系人
    contact_chose_all_btn = (By.ID, "check_all")
    def contact_chose_all(self):
        self.driver.find_element(*self.contact_chose_all_btn).click()

    # 删除按钮
    delete_btn = (By.ID, "delete")
    def delete_contact(self):
        self.driver.find_element(*self.delete_btn).click()
        self.driver.switch_to.alert.accept()

    #断言
    msg_locator=(By.CSS_SELECTOR,"body > div.container > div.alert.alert-success")
    def msg(self):
        return self.driver.find_element(*self.msg_locator).text